1
'/****************************** Module Header ******************************\
2 '* Module Name: AutoComplete.ashx.vb
3 '* Project: VBASPNETSerializeJsonString
4 '* Copyright (c) Microsoft Corporation
6 '* This project illustrates how to serialize Json string. we use jQuery at client
7 '* side and manipulate XML data at server side.
8 '* It demonstrates how to use the serializable json data through an autocomplete
11 '* This source is subject to the Microsoft Public License.
12 '* See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
13 '* All other rights reserved.
15 '\*****************************************************************************/
18 Imports System
.Web
.Services
19 Imports System
.Web
.Script
.Serialization
23 Public Class AutoComplete
24 Implements System
.Web
.IHttpHandler
26 Sub ProcessRequest(ByVal context
As HttpContext
) Implements IHttpHandler
.ProcessRequest
28 ' Query string 'term' is for autocomplete. By default, it sends the variable
29 ' "term" with the search word to the backend page.
30 Dim searchText
As String = context
.Request
.QueryString("term")
31 Dim books
As Collection
= New Collection
33 Dim ds
As New DataSet()
34 ds
.ReadXml(HttpContext
.Current
.Server
.MapPath("App_Data/books.xml"))
35 Dim dv
As DataView
= ds
.Tables(0).DefaultView
36 dv
.RowFilter
= [String].Format("title like '{0}*'", searchText
.Replace("'", "''"))
39 For Each myDataRow
As DataRowView
In dv
41 book
.id
= myDataRow("id").ToString()
42 book
.value
= myDataRow("title").ToString()
43 book
.label
= myDataRow("title").ToString()
44 book
.Author
= myDataRow("author").ToString()
45 book
.Genre
= myDataRow("genre").ToString()
46 book
.Price
= myDataRow("price").ToString()
47 book
.Publish_date
= myDataRow("publish_date").ToString()
48 book
.Description
= myDataRow("description").ToString()
52 Dim serializer
As JavaScriptSerializer
= New JavaScriptSerializer
53 Dim jsonString
As String = serializer
.Serialize(books
)
54 context
.Response
.Write(jsonString
)
58 ReadOnly
Property IsReusable() As Boolean Implements IHttpHandler
.IsReusable